define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'yiliao/doctor/index' + location.search,
                    add_url: 'yiliao/doctor/add',
                    edit_url: 'yiliao/doctor/edit',
                    del_url: 'yiliao/doctor/del',
                    multi_url: 'yiliao/doctor/multi',
                    import_url: 'yiliao/doctor/import',
                    table: 'yiliao_doctor',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'), operate: false},
                        {field: 'shop', title: __('Yiliao_shop_ids')},
                        // {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'name', title: __('Name'), operate: 'LIKE'},
                        {field: 'ename', title: __('英文名称'), operate: 'LIKE'},
                        {field: 'avatar', title: __('Avatar'), operate: 'LIKE', events: Table.api.events.image, formatter: Table.api.formatter.image},
                        // {field: 'price', title: __('Price'), operate: 'LIKE'},
                        {field: 'homedata', title: __('Homedata'), searchList: {"1":__('Homedata 1'),"0":__('Homedata 0')}, formatter: Table.api.formatter.normal},
                        // {field: 'jibie', title: __('Jibie'), operate: 'LIKE'},
                        // {field: 'tags', title: __('Tags'), operate: 'LIKE', formatter: Table.api.formatter.flag},
                        {field: 'area', title: __('面积'), operate: 'LIKE'},
                        //{field: 'kefu', title: __('Kefu'), operate: 'LIKE'},
                        //{field: 'admin_id', title: __('Admin_id')},
                        {field: 'status', title: __('Status'), searchList: {"normal":__('Normal'),"hidden":__('Hidden')}, formatter: Table.api.formatter.status},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,buttons:[
                            {
                                name:'daihui',
                                text:'排班',
                                //icon: 'fa fa-share',
                                classname: 'btn btn-xs btn-info btn-dialog',
                                extend:' target="_blank" data-area=\'["90%","90%"]\'',
                                url:function(row){
                                    return "yiliao/pblist/index?ids="+row.id;
                                },
                                visible:function(row){
                                    return true;
                                    if(row.status == 'no'){
                                        return true;
                                    }
                                }
                            },
                                // {
                                //     name:'daihui',
                                //     text:'请假',
                                //     //icon: 'fa fa-share',
                                //     classname: 'btn btn-xs btn-warning btn-dialog',
                                //     extend:' target="_blank"',
                                //     url:function(row){
                                //         return "yiliao/pbholiday/index?ids="+row.id;
                                //     },
                                //     visible:function(row){
                                //         return true;
                                //         if(row.status == 'no'){
                                //             return true;
                                //         }
                                //     }
                                // }
                            ]
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
